package cn.openea.perpartner.meily.web.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.openea.perpartner.meily.web.entity.Notice;
import cn.openea.perpartner.meily.web.mapper.NoticeMapper;
import cn.openea.perpartner.meily.web.service.INoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Notice)表服务实现类
 *
 * @author Weird077
 * @since 2023-01-11 11:17:22
 */
@Service("noticeService")
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {
    @Override
    public List<Notice> selectList(Notice notice) {
        LambdaQueryWrapper<Notice> wrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(notice.getTitle())){
            wrapper.like(Notice::getTitle,notice.getTitle());
        }
        if (StrUtil.isNotBlank(notice.getCreateUser())){
            wrapper.like(Notice::getCreateUser,notice.getCreateUser());
        }
        wrapper.orderByDesc(Notice::getUpdateTime);
        return list(wrapper);
    }

    @Override
    public List<Notice> getLastOne() {
        LambdaQueryWrapper<Notice> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Notice::getStatus, "on");
        wrapper.orderByDesc(Notice::getUpdateTime);
        return list(wrapper);
    }
}

